package 多线程;

public class X01多线程创建方式
{
	public static void main(String[]args){
		//继承式
		MyThread mt=new MyThread();
		mt.start();
		//实现接口式(推荐,因为实现接口还可以继承其他类)
		MyRunnable mr=new MyRunnable();
		Thread t1=new Thread(mr);
		t1.start();
	}
}
//继承Thread类
class MyThread extends Thread
{

	@Override
	public void run()
	{
		for(int i=0;i<50;i++){
			System.out.println(Thread.currentThread().getName()+"=="+i);//currentThread()返回当前线程getName获得线程名
			//线程休眠
			try
			{
				Thread.sleep(10);//单位毫秒，(毫秒,纳秒)
			}
			catch (InterruptedException e)
			{}
		}
	}
	
}
//实现Runnable接口
class MyRunnable implements Runnable
{
	@Override
	public void run()
	{
		for(int i=0;i<50;i++){
			System.out.println(Thread.currentThread().getName()+"=="+i);
			try
			{
				Thread.sleep(20);
			}
			catch (InterruptedException e)
			{}
		}
	}
}
